package design.patterns.structural;

/**
 * 桥接模式
 * 解释：
 * 桥接模式是一种结构型设计模式，
 * 可将一个大类或一系列紧密相关的类拆分为抽象和实现两个独立的层次结构， 从而能在开发时分别使用。
 */

/**
 * 情景
 * 铅笔可生产为 不同的形状 不同的颜色
 */
public class B_Bridge {
    public static void main(String[] args) {
        Pencil pencil = new Pencil(new PencilShape(ShapeType.LongType), new PencilColor(ColorChoice.Red));
        System.out.println(pencil);

        Pencil pencil1 = new Pencil(new PencilShape(ShapeType.ShortType), new PencilColor(ColorChoice.Pink));
        System.out.println(pencil);
    }
}
enum ShapeType{
     LongType("长矩形") ,
     ShortType("短矩形");
     private String shape;

    ShapeType(String shape) {
        this.shape = shape;
    }

    @Override
    public String toString() {
        return shape;
    }
}
enum ColorChoice{
    Red("红色"),
    Pink("粉红");
    private String color;

    ColorChoice(String color) {
        this.color = color;
    }

    @Override
    public String toString() {
        return color;
    }
}
interface Shape{
    void setShape(ShapeType shapeType);
}
interface Color{
    void setColor(ColorChoice color );

}
class PencilShape implements Shape{

    private ShapeType shapeType;

    public PencilShape(ShapeType shapeType) {
        this.shapeType = shapeType;
    }

    @Override
    public void setShape(ShapeType shapeType) {
        this.shapeType = shapeType;
    }

    @Override
    public String toString() {
        return "PencilShape{" +
                "shapeType=" + shapeType +
                '}';
    }
}

class PencilColor implements Color{
    private ColorChoice colorChoice;

    public PencilColor(ColorChoice colorChoice) {
        this.colorChoice = colorChoice;
    }

    @Override
    public void setColor(ColorChoice color) {
        this.colorChoice = color;
    }

    @Override
    public String toString() {
        return "PencilColor{" +
                "colorChoice=" + colorChoice +
                '}';
    }
}

class Pencil{
    private Shape shape;
    private Color color;

    public Pencil(Shape shape, Color color) {
        this.shape = shape;
        this.color = color;
    }

    @Override
    public String toString() {
        return "Pencil{" +
                "shape=" + shape +
                ", color=" + color +
                '}';
    }
}
